<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<%@ page language="java" contentType="text/html; charset=UTF-8"
		 pageEncoding="UTF-8"%>
<!DOCTYPE html>

<script src="js/jquery-1.11.3.min.js"></script>

<script type="text/javascript">

	function searchProductsByWord(obj) {
		var word = $(obj).val();
		var contentStr = "";
		if(null != word && word != ""){
		    $.ajax({
				url: "${pageContext.request.contextPath}/searchProduct",
				data: {"word":word},
				success:function (data) {
				    for(var i = 0 ; i < data.length ; i++){
                        contentStr += "<a href='${pageContext.request.contextPath}/productInfo?pid="+data[i].pid+"'><div style='font-size: 8px ; padding: 5px;' onmouseover='selectedFn(this)' " +
							"onmouseout='unSelectedFn(this)'>" + data[i].pname + "</div></a>"
                    }
				    $("#prod_content").html(contentStr);
				    $("#prod_content").css("display" , "block");
                } ,
				type: "post",
				dataType: "json"
			});
		}else{
            $("#prod_content").css("display" , "none");
        }
    }

    function selectedFn(obj) {
		$(obj).css("background" , "#2aabd2");
    }

    function unSelectedFn(obj) {
        $(obj).css("background" , "#ffffff");
    }
</script>
<!-- 登录 注册 购物车... -->

<div class="col-md-4">
</div>
<div class="container-fluid">
	<div class="col-md-5">
		<img src="img/header.png" />
	</div>
	<div class="col-md-3" style="padding-top:20px">
		<ol class="list-inline">
			<%--<%
				Object user = session.getAttribute("user");
				if(user == null) {
				    out.write("<li><a href=\"login.jsp\">登录</a></li>");
				    out.write("<li><a href=\"register.jsp\">注册</a></li>");
				    out.write("<li><a href=\"/cartList\">购物车</a></li>");
				    out.write("<li><a href=\"order_list.jsp\">我的订单</a></li>");
				} else {
					out.write("欢迎," + ((User)user).getName());
					out.write("<li><a href=\"\">购物车</a></li>");
					out.write("<li><a href=\"order_list.jsp\">我的订单</a></li>");
				}
			%> --%>
			<c:if  test="${user.uid==null ||user.uid==\"\"}">
			<li><a href="login.jsp">登录</a></li>
			<li><a href="register.jsp">注册</a></li>
            </c:if>
                <c:if  test="${user.uid!=null}">
					<li><a href="/loginout">登出</a></li>
                    <li><a href="#">欢迎  ${user.name}</a></li>
                </c:if>
			<li><a href="/cartList?uid=${user.uid}">购物车</a></li>
			<li><a href="/orderList?uid=${user.uid}">我的订单</a></li>
		</ol>
	</div>
</div>

<!-- 导航条 -->
<div class="container-fluid">
	<nav class="navbar navbar-inverse">
		<div class="container-fluid">
			<!-- Brand and toggle get grouped for better mobile display -->
			<div class="navbar-header">
				<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
					<span class="sr-only">Toggle navigation</span>
					<span class="icon-bar"></span>
					<span class="icon-bar"></span>
					<span class="icon-bar"></span>
				</button>
				<a class="navbar-brand" href="${pageContext.request.contextPath}/home">首页</a>
			</div>

			<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
				<ul class="nav navbar-nav">
					<c:forEach items="${categoryList}" var="cg">
						<li><a href="${pageContext.request.contextPath}/productList?cid=${cg.cid}">${cg.cname}</a></li>
					</c:forEach>
				</ul>
				<form class="navbar-form navbar-right" role="search">
					<div class="form-group" style="position: relative">
						<input type="text" class="form-control" placeholder="Search" onkeyup="searchProductsByWord(this)"/>
						<!--position : 让出位置，防止挤乱布局  z-index ： 图层设定，正整数越大，优先级越高-->
						<div id="prod_content" style="width: 196px ;  background: white; margin-top: 2px ;
							 display: none;
						     position: absolute; z-index: 1000" ></div>
					</div>
					<button type="submit" class="btn btn-default">Submit</button>
				</form>
			</div>
		</div>
	</nav>
</div>